package designPatterns.P17_备忘录模式_Memento;

/**
 * https://www.runoob.com/design-pattern/memento-pattern.html
 * @author d11yu
 */
public class P01 {
    public static void main(String[] args) {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("State #1");
        originator.setState("State #2");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #3");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #4");
        System.out.println("Current state: " + originator.getState());
        originator.setStateFromMemento(careTaker.get(0));
        System.out.println("First saved state: " + originator.getState());
        originator.setStateFromMemento(careTaker.get(1));
        System.out.println("Second saved state: " + originator.getState());
    }
}
